package com.fh.wanandroid.base;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import javax.inject.Inject;

import butterknife.ButterKnife;
import butterknife.Unbinder;

public abstract class BaseActivity <P extends BasePresenter> extends AppCompatActivity {

    @Inject
    protected P mPresenter;

    private Unbinder mUnbinder;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        mUnbinder= ButterKnife.bind(this);
        mPresenter = getmPresenter();
        presenterSetView();
        initView();
        initData();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(mUnbinder != null)
            mUnbinder.unbind();
        if(mPresenter!=null)
            mPresenter.removeView();
    }

    public abstract P getmPresenter();

    public abstract void presenterSetView();

    public abstract void initView();

    public abstract void initData();

    public abstract int getLayoutId();
}
